<template>
	<view class="">
		<!-- 底部分段器 -->
		<view class="row" style="margin-top: 30rpx;">
			<view class="size30 font500 minauto" :class="tabshow == 0 ? 'col_tab' : 'col0'" @click="onTab(0)">
				已发布
				<view class="mintop10" :class="tabshow == 0 ? 'tab' : ''">
				</view>
			</view>
			<view class="size30 font500 minauto" :class="tabshow == 1 ? 'col_tab' : 'col0'" @click="onTab(1)">
				审核中
				<view class="mintop10" :class="tabshow == 1 ? 'tab ' : ''">
				</view>
			</view>
		</view>
		<!-- 底部分段器 -->
		<!-- 列表 -->
		<view class="min30_rl mintop30">
			<view v-for="(item,index) in list" @click="onNav(item.id)">
				<view class="rad2 minbottom30 row"
					style="background-color: #fff;box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);"
					v-if="item.appletCategory.title == '农机'">
					<image :src="item.full_images" style="width: 35%;height: 240rpx;border-radius: 20rpx 0 0 20rpx;">
					</image>
					<view class="column" style="padding: 20rpx;width: 59%;">
						<view class="row">
							<view class="font700 size30 col0 omit1" style="max-width: 240rpx;">
								{{ item.name }}
							</view>
							<view class="font500 size24 disflex align rad2 minleft20"
								style="background-color: #FFF3C9;color: #FF7A00;padding: 0 20rpx;">
								{{ item.price }}
							</view>
						</view>
						<view class="minto minbottom0">
							<view class="row size26 font500 align minbottom10" style="color: #808080;">
								司机：{{ item.driver }}
							</view>
							<view class="row size24 font500 align minbottom10" style="color: #808080;">
								{{ item.land_location_text }}
							</view>
							<view class="row size24 font500 align" style="color: #FF7A00;">
								合作社已认证
								<!-- <view class="minau minright0 col0">
									{{ item.distance }}
								</view> -->
							</view>
						</view>
					</view>
				</view>
				<view class="rad2 minbottom30 row"
					style="background-color: #fff;box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);" v-else>
					<image :src="item.full_images" style="width: 35%;height: 240rpx;border-radius: 20rpx 0 0 20rpx;">
					</image>
					<view class="column" style="padding: 20rpx;width: 59%;">
						<view class="font700 size30 col0 minbottom10 omit1">
							{{ item.name }}
						</view>
						<view class="row">
							<view class="font500 size22 rad2"
								style="background-color: #DEEFD6;color: #60884D;padding: 2rpx 14rpx;">
								{{ item.appletCategory.title }}
							</view>
							<view class="font500 size22 rad2 minleft10"
								style="background-color: #FFF3C9;color: #FF7A00;padding: 2rpx 14rpx;">
								{{ Pitem.method == 1 ? '转让' : '出租' }}
							</view>
						</view>
						<view class="minto minbottom0">
							<view class="row size22 font500 align minbottom10" style="color: #808080;">
								<view class="size24" style="color: #FF2D10;">
									￥
								</view>
								<view class="size28 font700" style="color: #FF2D10;">
									{{ item.price }}
								</view>
								<!-- <view class="size24 col3 minleft10 font500">
									元/亩/年
								</view> -->
								<view class="minau minright0" v-if="item.term">
									{{ item.term }}年
								</view>
							</view>
							<view class="row size22 font500 align" style="color: #808080;">
								<view class="row align" v-if="item.acres">
									<image src="@/static/index/land.png" mode="" style="width: 30rpx;height: 30rpx;">
									</image>
									{{ item.acres }}
								</view>
								<view class="minau minright0 omit1" style="width: 300rpx;text-align: right;">
									{{ item.land_location_text }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 列表 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabshow: 0,
				user_id: '',
				page: 1,
				status: 'loadmore',
				loadmore: [],
				list: []
			}
		},
		onLoad() {

		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			if (this.user_id) {
				//如果存在token
				this.getSellList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {
				this.$com.toast('您还未登录，正在前往登录')
				setTimeout(() => {
					this.$jump.nav('/mypackage/sign')
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getSellList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getSellList() {
				let {
					code,
					msg,
					data
				} = await this.$com.fetchGet("AppletUser/GetUserRentList", {
					page: this.page,
					user_id: this.user_id,
					is_type: this.tabshow == 0 ? 1 : 0
				})
				if (code == 1) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else {
					console.log(msg);
				}
			},
			onNav(id) {
				// console.log(id, appletCategory);
				if (this.tabshow == 0) {
					setTimeout(() => {
						this.$jump.nav('/indexpackage/sell_info?id=' + id)
					}, 1000)
				} else {
					this.$com.toast('该发布还在审核中！')
				}
			},
			onTab(i) {
				this.tabshow = i
				this.page = 1
				this.getSellList()
			}
		}
	}
</script>

<style scoped lang="less">
	.col_tab {
		color: #FAB029;
	}

	.tab {

		height: 4rpx;
		background-color: #FAB029;
		border-radius: 20rpx;
	}
</style>